package com.xiao.androidcompose01.di

import android.app.Application
import com.tencent.trtc.TRTCCloud
import com.xiao.androidcompose01.net.plugin.AuthenticationPlugin
import io.ktor.client.HttpClient
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.plugins.DefaultRequest
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.http.URLProtocol
import io.ktor.serialization.kotlinx.json.json
import kotlinx.serialization.json.Json
import okhttp3.logging.HttpLoggingInterceptor
import org.koin.core.annotation.Single

@Single
fun provideHttpClient(): HttpClient{
   return HttpClient(OkHttp){
      install(DefaultRequest){
         url{
            host = "150.158.43.174"
            port = 8080
            protocol = URLProtocol.HTTP
         }
      }
      install(AuthenticationPlugin)
      install(ContentNegotiation){
         json(Json {
            isLenient = true
            ignoreUnknownKeys = true
         })
      }
      
      engine {
         val log = HttpLoggingInterceptor()
         log.setLevel(HttpLoggingInterceptor.Level.BODY)
         addInterceptor(log)
         
         config {
         
         }
         
      }
   }
   
}



@Single
fun provideTRTCloud(context: Application): TRTCCloud {
   val cloud = TRTCCloud.sharedInstance(context)
   return cloud
}